package com.csc.banking.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.csc.banking.dao.RoleDAO;
import com.csc.banking.domain.Role;
import com.csc.banking.util.CustomEntityManager;

@Repository
@Transactional
public class RoleDAOImpl extends CustomEntityManager implements RoleDAO {

	@Override
	public List<Role> getAllRoles() {
		return getEntityManager().createQuery("From Role", Role.class).getResultList();
	}

	@Override
	public Role getRole(int idRole) {
		return getEntityManager().find(Role.class, idRole);
	}

	@Override
	public void addRole(Role role) {
		getEntityManager().persist(role);
	}

	@Override
	public void updateRole(Role role) {
//		Role r = getRole(role.getIdRole());
//		r.setRoleName(role.getRoleName());
//		r.setDescription(role.getDescription());
		
		getEntityManager().merge(role);
	}

	@Override
	public void deleteRole(int idRole) {
		Role role = getRole(idRole);
		getEntityManager().remove(role);
	}

}
